//Created by Koza
//The world holds a 2D array of nodes
#pragma once

//Needs access to the objects and other members of the object.h
#include <Windows.h>
#include <assert.h>
#include "Wall.h"

extern int WORLD_HEIGHT;
extern int WORLD_WIDTH;

const int AmountWalls = 2;
const int PosMod = 30;

//The Node is used by the world to section off every location and store its data.
// The amount of Nodes in game are determined randomly each time the map is generated
//
// A Node has 4 walls and 4 fillers. A filler is a 3D object that sits in the corners 
// for aesthetics. The walls are controlled by the world at generation time. If a wall
// is "broken down" or set to false, the object is removed and is not allowed to draw or 
// enter the collision list.
class Node
{
private:
	//Used to determine if this node has been visited yet or not
	bool			m_bVisited;
	//Used to determine if a direction is available to generate in
	bool			m_bNorth;
	bool			m_bSouth;
	bool			m_bEast;
	bool			m_bWest;

	Wall**			m_clppMyWalls;
	Wall**			m_clppFillers;

public:
	//Base Constructor/Deconstructor
	Node();
	~Node();

	//Refreshes/Rebuilds all the walls as default
	void Reset(){Init(0,0);}

	//Called in constructor and reset
	void Init(int WorldX,int WorldY);

	//Used to put bricks in the vectors
	inline bool	CheckBrick(int x,int y)
	{
		if(m_clppMyWalls[y][x].m_bActive)return true;
			else return false;
	}
	inline bool CheckFiller(int x,int y)
	{
		if(m_clppFillers[y][x].m_bActive)return true;
			else return false;
	}
	inline Wall* GetBrick(int x,int y){return &m_clppMyWalls[y][x];}
	inline Wall* GetFiller(int x,int y){return &m_clppFillers[y][x];}
	//Checks if the node has been visited
	inline bool wasVisited(){return m_bVisited;}
	
	//Sets whether the Node was visited or not
	inline void SetVisitState(bool V){m_bVisited = V;}

	//Checks if any of the directions are true
	// if they are it means movement in a direction is possible
	bool CanGoDirection();

	//Checks if the direction bool is true
	// Direction is an enum with all four directions
	bool CanGoDirection(eDirections Direction);
	
	//Sets the directional Value to value given
	// Direction is an enum with all four directions
	void SetDirection(eDirections Direction,bool D);

	//Returns the coordinates on the wall array of that node for that direction
	COORD getNorthCoord()
	{
		COORD N;
		N.X = 0;
		N.Y = 0;
		return N;
	}
	COORD getSouthCoord()
	{
		COORD S;
		S.X = 1;
		S.Y = 0;
		return S;
	}
	COORD getEastCoord()
	{
		COORD E;
		E.X = 1;
		E.Y = 1;
		return E;
	}
	COORD getWestCoord()
	{
		COORD W;
		W.X = 0;
		W.Y = 1;
		return W;
	}
	inline COORD GetCoord(eDirections Direction)
	{
		switch(Direction)
		{
		case NORTH:
			return getNorthCoord();		
			break;
		case SOUTH:
			return getSouthCoord();
			break;
		case EAST:
			return getEastCoord();
			break;
		case WEST:
			return getWestCoord();
			break;
		}
		return COORD();
	}

	//Sets this directions wall to down
	// Also if the node is counted as not visited its
	// set to visited upon breaking a wall down
	void BreakWall(eDirections Direction);
};